import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 全局共享当前登录的用户名
    islogin: sessionStorage.getItem("islogin"),
    unickname: sessionStorage.getItem("unickname"), //用户名
    uid: sessionStorage.getItem("uid"),
    uname: sessionStorage.getItem("uname"),
    upwd: sessionStorage.getItem("upwd"),
    gender: sessionStorage.getItem("gender"),
    avatar_pic: sessionStorage.getItem("avatar_pic"),

    shopCar_vuex: [],
  },
  // 在登录成功，把用户名设置给uname变量
  mutations: {
    // Vuex要求：修改state中存储值，必须使用mutations中声明的方法
    // 参数1：固定为state,代表当前的state属性
    // 剩余参数：看具体使用时的参数传递
    updateUname(state, newName) {
      state.unickname = newName;
    },
    updateIsloginState(state, newState) {
      state.islogin = newState;
    },
    updateUid(state, newUid) {
      state.uid = newUid;
    },
    updateShopCar(state, newData) {
      state.shopCar_vuex = newData;
    },
  },
  actions: {},
  modules: {},
});
